from rss_reader.database.models import Article, Feed
class DataBaseManager:
    """database manager
    """
    def __init__(self, session_factory):
        self.session_factory = session_factory
        self.session = self.session_factory()

    def toggle_starred(self, article_id: int):
        """
        toggle star tag of article
        :param article_id:
        :return:
        """
        article = self.session.query(Article).get(article_id)
        article.starred = not article.starred
        self.session.commit()

    def toggle_read(self, article_id: int):
        """
        toggle read tag of article
        :param article_id:
        :return:
        """
        article = self.session.query(Article).get(article_id)
        article.read = not article.read
        self.session.commit()

    def mark_read(self, article_id: int):
        """
        mark read tag of article
        :param article_id:
        :return:
        """
        article = self.session.query(Article).get(article_id)
        article.read = True
        self.session.commit()

    def mark_read_articles(self, articles):
        """
        makr articles read
        :param articles:
        :return:
        """
        for article in articles:
            article.read = True
        self.session.commit()
